<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<select id="menulist">
  <option id="item0">Alicia</option>
  <option id="item1">Peter</option>
  <option id="item2">Kalinda</option>
</select>
<script>
async_test(function(t)
{
    var menulist = document.getElementById("menulist");
    menulist.selectedIndex = 0;
    menulist.focus();

    var roleToExpectedNotifications = new Map();
    roleToExpectedNotifications.set("AXRole: AXMenuListPopup", new Set(["ActiveDescendantChanged"]));
    roleToExpectedNotifications.set("AXRole: AXMenuListOption", new Set(["MarkDirty"]));
    accessibilityController.addNotificationListener(function listener(element, notification) {
        let expectedNotifications = roleToExpectedNotifications.get(element.role);
        if (!expectedNotifications)
          return;

        if (element.role == 'AXRole: AXMenuListOption' && notification == 'MarkDirty')
          assert_equals(element.name, "Alicia");

        expectedNotifications.delete(notification);
        if (!expectedNotifications.size)
          roleToExpectedNotifications.delete(element.role);

        if (!roleToExpectedNotifications.size)
            t.done();
    });

    var axMenuList = accessibilityController.accessibleElementById("menulist");
    eventSender.mouseMoveTo(axMenuList.x + 10, axMenuList.y + 10);
    eventSender.mouseDown();
    eventSender.mouseUp();
}, "menu list fires correct events on open");
</script>
